package com.Prot2.Logger;

import com.Prot2.Globals;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;

public class HumidityWorker {
		
		private SensorManager mSensorManager;
		private float rH;
		
		public HumidityWorker(Context c){
	    	mSensorManager= (SensorManager) c.getSystemService(Context.SENSOR_SERVICE);
	    	mSensorManager.registerListener(mHumidityListener, mSensorManager.getDefaultSensor(Sensor.TYPE_RELATIVE_HUMIDITY),Globals.samplingRate*1000);

		}
		
		private SensorEventListener mHumidityListener = new SensorEventListener() {

			@Override
			public void onAccuracyChanged(Sensor arg0, int arg1) {
				// TODO Auto-generated method stub
			}

			@Override
			public void onSensorChanged(SensorEvent event) {
				if(event.sensor.getType() == Sensor.TYPE_RELATIVE_HUMIDITY){
					rH = event.values[0];
				}
			}
			
		};
		
		public float getRH(){
			return rH;
		}
		
		public String getRead(String DELIMITER){
			return ""+rH;
		}
		
		public void stop(){
			mSensorManager.unregisterListener(mHumidityListener);
		}
		
	}

